<?php
$search = stripos(current_url(), 'search') ? '/search?keyfield=' . $keyfield . '&keyword=' . $keyword . '&' : '?';
$controller = substr($active, 0, strlen($active) - 2) . $search;
if ($page_total <= 10) {
	$first_index = 1;
	$last_index = $page_total;
} else {
	$first_index = $page_current - 4;
	$last_index = $page_current + 5;
}
while ($first_index < 1) {
	$first_index++;
	$last_index++;
}
while ($last_index > $page_total) {
	$first_index--;
	$last_index--;
}
?>
<center>
<div class="btn-group">
<?php echo anchor(site_url($controller . 'page=1'), '&laquo;', array('class' => 'btn btn-default'));?>
<?php echo anchor(site_url($controller . 'page=' . ($page_current == 1 ? 1 : $page_current - 1)), '&lsaquo;', array('class' => 'btn btn-default'));?>
<div class="btn-group dropup">
	<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
      <span id="keyfield"><?php echo '第 ' . $page_current . ' 页';?></span>
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
<?php for ($i = $last_index; $i >= $first_index; $i--):?>
<li<?php if ($i == $page_current) {echo ' class="active"';
}
?>>
<?php echo anchor(site_url($controller . 'page=' . $i), '第 ' . $i . ' 页');?>
</li>
<?php endfor;?>
</ul>
    </div>
<?php echo anchor(site_url($controller . 'page=' . ($page_current == $page_total ? $page_total : $page_current + 1)), '&rsaquo;', array('class' => 'btn btn-default'));?>
<?php echo anchor(site_url($controller . 'page=' . $page_total), '&raquo;', array('class' => 'btn btn-default'));?>
</div>
</center>